import eslint from '@eslint/js';
import vue from 'eslint-plugin-vue';
import typescript from '@typescript-eslint/eslint-plugin';
import prettier from 'eslint-config-prettier'; 
import parserVue from 'vue-eslint-parser';
import parserTs from '@typescript-eslint/parser';

export default [
  eslint.configs.recommended, 

  // 处理 .prettierrc.js 的 Node 环境
  {
    files: ['.prettierrc.js'],
    languageOptions: {
      globals: {
        module: 'readonly',
      },
      parserOptions: {
        sourceType: 'commonjs',
      },
    },
  },

  {
    file: ['commitlint.config.js'],
    languageOptions: {
    env: {
      node: true // 启用 Node.js 环境，让 module 被识别
    }
  }
  },

  {
    files: ['**/*.vue', '**/*.ts'], 
    languageOptions: {
      parser: parserVue,
      parserOptions: {
        parser: parserTs, 
        ecmaVersion: 'latest',
        sourceType: 'module',
      },
      globals: {
        window: 'readonly',
        document: 'readonly',
        console: 'readonly',
        localStorage: 'readonly',
        setInterval: 'readonly',
        clearInterval: 'readonly',
        setTimeout: 'readonly',
      },
    },
    plugins: { vue, '@typescript-eslint': typescript }, 
    rules: {
      ...vue.configs['flat/strongly-recommended'].rules, // 替代或补充 essential
      ...vue.configs['flat/essential'].rules, 
      ...typescript.configs.recommended.rules, 
      'vue/multi-word-component-names': 'off', 
      '@typescript-eslint/no-explicit-any': 'warn'
    },
  },
  prettier, 
];